import 'dart:ui';

// import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:surfaceim/common/values/values.dart';
import 'package:surfaceim/common/widgets/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'index.dart';

class SignInPage extends GetView<SignInController> {
  // logo
  Widget _buildLogo() {
    return Container(
      width: 110.w,
      margin: EdgeInsets.only(top: (40 + 44.0).h), // 顶部系统栏 44px
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Container(
            height: 76.w,
            width: 76.w,
            margin: EdgeInsets.symmetric(horizontal: 15.w),
            child: Stack(
              alignment: Alignment.center,
              children: [
                Positioned(
                  left: 0,
                  top: 0,
                  right: 0,
                  child: Container(
                    height: 76.w,
                    decoration: BoxDecoration(
                      color: AppColors.primaryBackground,
                      boxShadow: [
                        Shadows.primaryShadow,
                      ],
                      borderRadius: BorderRadius.all(
                          Radius.circular((76 * 0.5).w)), // 父容器的50%
                    ),
                    child: Container(),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  // 登录表单
  Widget _buildInputForm() {
    return Container(
      width: 295.w,
      // height: 204,
      margin: EdgeInsets.only(top: 49.h),
      child: Column(
        children: [
          // email input
          inputTextEdit(
            controller: controller.emailController,
            keyboardType: TextInputType.emailAddress,
            hintText: "Email",
            marginTop: 0,
            // autofocus: true,
          ),
          // password input
          inputTextEdit(
            controller: controller.passController,
            keyboardType: TextInputType.visiblePassword,
            hintText: "Password",
            isPassword: true,
          ),

          // 注册、登录 横向布局
          Container(
            height: 44.h,
            margin: EdgeInsets.only(top: 15.h),
            child: Row(
              children: [
                // 注册
                btnFlatButtonWidget(
                  onPressed: controller.handleNavSignUp,
                  gbColor: AppColors.thirdElement,
                  title: "Sign up",
                ),
                Spacer(),
                // 登录
                btnFlatButtonWidget(
                  onPressed: controller.handleSignIn,
                  gbColor: AppColors.primaryElement,
                  title: "Sign in",
                ),
              ],
            ),
          ),
          // Spacer(),

          // Fogot password
          Padding(
            padding: EdgeInsets.only(top: 8.0),
            child: TextButton(
              onPressed: controller.handleFogotPassword,
              child: Text(
                "Fogot password?",
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: AppColors.secondaryElementText,
                  fontFamily: "Avenir",
                  fontWeight: FontWeight.w400,
                  fontSize: 16.sp,
                  height: 1, // 设置下行高，否则字体下沉
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: Stack(
        children: [
          // 视频组件
          // VideoBackGround(controller: controller.chewieController),
          // 高斯模糊蒙层
          LoginMantle(),
          // 登录 widgets
          // LoginWidget(),
          Center(
            child: Column(
              children: <Widget>[
                _buildLogo(),
                _buildInputForm(),
                Spacer(),
                ThirdPartyLogin(),
                // _buildSignupButton(),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

class LoginMantle extends StatelessWidget {
  const LoginMantle({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BackdropFilter(
      filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
      child: Container(
        width: Get.width,
        height: Get.height,
      ),
    );
  }
}

class VideoBackGround extends StatefulWidget {
  VideoBackGround({Key? key, this.controller}) : super(key: key);
  final controller;
  @override
  _VideoBgState createState() => _VideoBgState();
}

class _VideoBgState extends State<VideoBackGround> {
  // var _controller;
  @override
  void initState() {
    super.initState();
    // _controller = widget.controller;
  }

  @override
  Widget build(
    BuildContext context,
  ) {
    return SingleChildScrollView(
      physics: NeverScrollableScrollPhysics(),
      child: Container(
        // color: Colors.orange,
        width: Get.width,
        height: Get.height,
        // child: Chewie(
        //   controller: _controller,
        // ),
      ),
    );
  }
}



// 全切圆角
// Container(
// decoration: ShapeDecoration(
//     shape: ContinuousRectangleBorder(
//   borderRadius: BorderRadius.circular(100.0),
//   side: BorderSide(
//     width: 0,
//     color: Colors.black12,
//     style: BorderStyle.solid,
//   ),
// )),
// child :
